package com.hwl.eduservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwl.eduservice.feign.VodMediaService;
import com.hwl.eduservice.mapper.VideoMapper;
import com.hwl.eduservice.pojo.Video;
import com.hwl.eduservice.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author long
 * @since 2021-09-21
 */
@Slf4j
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {

    @Resource
    private VodMediaService vodMediaService;

    @Override
    public boolean removeVideoById(String id) {
        Video video = baseMapper.selectById(id);

        if (video != null && !StringUtils.isEmpty(video.getVideoSourceId())) {
            Boolean flag = vodMediaService.removeVideo(video.getVideoSourceId()).getSuccess();
            log.info(flag ? "远程调用删除课时视频成功！" : "远程调用删除课时视频失败！");
        }
        return true;
    }
}
